﻿
using System.Collections.Generic;
using UnityEngine;

public class CanvasChangeLayer : MonoBehaviour
{
	string layerName;
	List<Canvas> cList = new List<Canvas>();
	int count;
	void Start()
	{
	}
	public void SetLayer(string layerName)
	{
		this.layerName = layerName;
		count = 0;
		Update();
	}
	void Update()
	{
		GetComponentsInChildren(true, cList);
		if (count == cList.Count) return;
		count = cList.Count;
		for (int i = 0; i < cList.Count; i++)
		{
			var c = cList[i];
			c.sortingLayerName = layerName;
		}
	}
}
